//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "Finland.h"
using namespace Cephei::QL::Times::Calendars;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Times/Calendar.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Calendars::CFinland::CFinland () : CCalendar(CFinland::typeid)
{
    try
    {
#ifdef HANDLE
        _phFinland = NULL;
#endif
        _ppFinland = new boost::shared_ptr<QuantLib::Finland> (new QuantLib::Finland ( ));
        SetCalendar (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppFinland));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Calendars::CFinland::CFinland (boost::shared_ptr<QuantLib::Finland>& childNative, Object^ owner) : CCalendar(CFinland::typeid)
{
#ifdef HANDLE
	_phFinland = NULL;
#endif
	_ppFinland = &childNative;
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppFinland));
}
Cephei::QL::Times::Calendars::CFinland::CFinland (QuantLib::Finland& childNative, Object^ owner) : CCalendar(CFinland::typeid)
{
#ifdef HANDLE
	_phFinland = NULL;
#endif
	_ppFinland = new boost::shared_ptr<QuantLib::Finland> (&childNative);
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppFinland));
    _FinlandOwner = owner;
    _CalendarOwner = owner;
}

Cephei::QL::Times::Calendars::CFinland::CFinland (CFinland^ copy) : CCalendar(CFinland::typeid)
{
#ifdef HANDLE
	_phFinland = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFinland = new boost::shared_ptr<QuantLib::Finland> (copy->GetShared());
        _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppFinland));
    }
}
Cephei::QL::Times::Calendars::CFinland::CFinland (PLATFORM::Type^ t) : CCalendar(CFinland::typeid)
{
#ifdef HANDLE
	_phFinland = NULL;
#endif
	if (!t->IsSubclassOf(CFinland::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Calendars::CFinland::CFinland (QuantLib::Handle<QuantLib::Finland>& childNative, Object^ owner)  : CCalendar(CFinland::typeid)
{
	_phFinland = &childNative;
	_ppFinland = &static_cast<boost::shared_ptr<QuantLib::Finland>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppFinland));
    _FinlandOwner = owner;
}
Cephei::QL::Times::Calendars::CFinland::CFinland (QuantLib::Handle<QuantLib::Finland> childNative)  : CCalendar(CFinland::typeid)
{
	_phFinland = &childNative;
	_ppFinland = &static_cast<boost::shared_ptr<QuantLib::Finland>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppFinland));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Calendars::CFinland::CFinland (QuantLib::Finland childNative)  : CCalendar(CFinland::typeid)
{
#ifdef HANDLE
	_phFinland = NULL;
#endif
	_ppFinland = new boost::shared_ptr<QuantLib::Finland> (new QuantLib::Finland (childNative));
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppFinland));
}
#endif

Cephei::QL::Times::Calendars::CFinland::~CFinland ()
{
    if (_ppFinland != NULL)
    {
	    delete _ppFinland;
        _ppFinland = NULL;
    }
}
Cephei::QL::Times::Calendars::CFinland::!CFinland ()
{
    if (_ppFinland != NULL)
    {
	    delete _ppFinland;
    }
}
QuantLib::Finland& Cephei::QL::Times::Calendars::CFinland::GetReference ()
{
    if (_ppFinland == NULL) throw REFNEW NativeNullException ();
	return **_ppFinland;
}
boost::shared_ptr<QuantLib::Finland>& Cephei::QL::Times::Calendars::CFinland::GetShared ()
{
    if (_ppFinland == NULL) throw REFNEW NativeNullException ();
	return *_ppFinland;
}
QuantLib::Finland* Cephei::QL::Times::Calendars::CFinland::GetPointer ()
{
    if (_ppFinland == NULL) throw REFNEW NativeNullException ();
	return &**_ppFinland;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Finland>& Cephei::QL::Times::Calendars::CFinland::GetHandle ()
{
	if (_phFinland == NULL)
	{
		_phFinland = new Handle<QuantLib::Finland> (*_ppFinland);
	}
	return *_phFinland;
}
#endif
bool Cephei::QL::Times::Calendars::CFinland::HasNative () 
{
	return (_ppFinland != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Calendars::IFinland^ Cephei::QL::Times::Calendars::CFinland_Factory::Create ()
{
    return REFNEW CFinland ();
}
